#!/usr/bin/env python

import unittest
from template import Template
import util

class TestTemplate(Template, unittest.TestCase):
  def __init__(self, *args, **kwargs):
    unittest.TestCase.__init__(self, *args, **kwargs)
    Template.__init__(self)

  def setUp(self):
    #print "setUp"
    pass

  def tearDown(self):
    #print "tearDown"
    pass

  def test_listTemplates(self):
    templatefilter = "self"
    response = self.listTemplates(templatefilter)
    self.assertTrue(response["count"]>0 or len(response) == 0)

  def test_createTemplate(self):
    snapshotid = 4 
    name = "sn_" + util.getUniqueStr()
    displaytext = "d" + name
    ostypeid = 20 
    response = self.createTemplate(snapshotid, name, displaytext, ostypeid)
    #self.assertTrue(response["snapshotid"], snapshotid)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["displaytext"], displaytext)
    self.assertEqual(response["ostypeid"], ostypeid)

  def test_updateTemplate(self):
    templateid = 203 
    name = "sn_" + util.getUniqueStr()
    displaytext = "d" + name
    response = self.updateTemplate(templateid, name, displaytext)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["displaytext"], displaytext)
    
  def test_deleteTemplate(self):
    templateid = 205
    response = self.deleteTemplate(templateid)
    self.assertEqual(response["success"], True)

  def test_createServiceOffering(self):
    cpunumber = 2
    cpuspeed = 2000 
    memory = 300
    name = "so_" + util.getUniqueStr()
    displaytext = "d" + name
    response = self.createServiceOffering(cpunumber, cpuspeed, memory, name, displaytext)
    self.assertEqual(response["cpunumber"], cpunumber)
    self.assertEqual(response["cpuspeed"], cpuspeed)
    self.assertEqual(response["memory"], memory)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["displaytext"], displaytext)

  def test_listServiceOfferings(self):
    response = self.listServiceOfferings()
    self.assertTrue(len(response) == 0 or response["count"] > 0)

  def test_updateServiceOffering(self):
    serviceofferingid = 11 
    name = "sn_" + util.getUniqueStr()
    displaytext = "d" + name
    response = self.updateServiceOffering(serviceofferingid, name, displaytext)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["displaytext"], displaytext)

  def test_deleteServiceOffering(self):
    serviceofferingid = 11
    response = self.deleteServiceOffering(serviceofferingid)
    self.assertEqual(response["success"], "true")

  def test_createDiskOffering(self):
    name = "do_" + util.getUniqueStr()
    displaytext = "d" + name
    disksize = 3
    customized = True #False
    response = self.createDiskOffering(name, displaytext, disksize, customized)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["displaytext"], displaytext)
    self.assertEqual(response["disksize"], disksize)
    self.assertEqual(response["iscustomized"], customized)

  def test_listDiskOfferings(self):
    response = self.listDiskOfferings()
    self.assertTrue(len(response) == 0 or response["count"] > 0)

  def test_updateDiskOffering(self):
    diskofferingid = 14
    name = "dn_" + util.getUniqueStr()
    displaytext = "d" + name
    response = self.updateDiskOffering(diskofferingid, name, displaytext)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["displaytext"], displaytext)

  def test_deleteDiskOffering(self):
    diskofferingid = 14
    response = self.deleteDiskOffering(diskofferingid)
    self.assertEqual(response["success"], "true")



def get_suite():
  suite = unittest.TestSuite()
  #suite.addTest(TestTemplate("test_listTemplates"))
  #suite.addTest(TestTemplate("test_createTemplate"))
  #suite.addTest(TestTemplate("test_updateTemplate"))
  #suite.addTest(TestTemplate("test_deleteTemplate"))
  suite.addTest(TestTemplate("test_createServiceOffering"))
  #suite.addTest(TestTemplate("test_listServiceOfferings"))
  #suite.addTest(TestTemplate("test_updateServiceOffering"))
  #suite.addTest(TestTemplate("test_deleteServiceOffering"))
  #suite.addTest(TestTemplate("test_createDiskOffering"))
  #suite.addTest(TestTemplate("test_listDiskOfferings"))
  #suite.addTest(TestTemplate("test_updateDiskOffering"))
  #suite.addTest(TestTemplate("test_deleteDiskOffering"))

  return suite

if __name__ == "__main__":
  suite = get_suite()
  runner = unittest.TextTestRunner()
  runner.run(suite)
